// Copyright (C) joyinter
// All rights reserved.
// 
// Author : Lu Rong
// Date   : 2005-02-22

#ifndef __MSVR_CSTRENCH_H_SERVER_SVR_MAIN__
#define __MSVR_CSTRENCH_H_SERVER_SVR_MAIN__

#pragma once

#include <common/netmsg/netmsg.h>
#include <common/svr_base/net_transmit.h>

namespace JoyServer
{

class CJoyMainRoom;

class CJoyCSTrench
{
public:
	CJoyMainRoom	*m_room;

	// the map active or not
	bool	m_active;
	// need trans data or not
	bool	m_bmodify;

	// the cs server
	UINT	m_srcUser;
	UINT	m_svrPort;

	// trans data
	UINT	m_roomId;
	UINT	m_trenchId;
	CString	m_trenchName;

	CString	m_gameName;
	CString	m_csMapName;
	UINT	m_playingCount;
	UINT	m_maxPlayerCount;
	UINT	m_spectatorCount;
	UINT	m_sortCount;

	class CCSPlayer
	{
	public:
		UINT	m_playId;		
		CString	m_playerCSName;
		UINT	m_userId;
		CString	m_userName;
		UINT	m_playRole;
		UINT	m_killCount;
		UINT	m_bekillCount;
		LONG	m_playTime;
		CCSPlayer() : m_playId(0), m_playRole(0), m_killCount(0), m_bekillCount(0), m_playTime(0), m_userId(0)
		{}
		CCSPlayer(UINT nPlayId, UINT nUserId) : m_playId(nPlayId), m_userId(nUserId), m_killCount(0), m_bekillCount(0), m_playTime(0), m_playRole(0)
		{}
		CCSPlayer(UINT nPlayId, CString strPlayerCSName, UINT nUserId, CString strUserName, UINT nRole, UINT nKillCount, UINT nBekillCount, long nPlayTime) :
				m_playId(nPlayId), m_playerCSName(strPlayerCSName), m_userId(nUserId), m_userName(strUserName), m_playRole(nRole), m_killCount(nKillCount), m_bekillCount(nBekillCount), m_playTime(nPlayTime)
		{}
		CCSPlayer(CCSPlayer &player)
		{
			m_playId = player.m_playId;
			m_playRole = player.m_playRole;
			m_userId = player.m_userId;
			m_userName = player.m_userName;
			m_playerCSName = player.m_playerCSName;
			m_killCount = player.m_killCount;
			m_bekillCount = player.m_bekillCount;
			m_playTime = player.m_playTime;
		}

		bool operator == (const CCSPlayer &player) const throw()
		{
			if (m_userId == player.m_userId)// && m_playId == player.m_playId)
				return true;
			else
				return false;
		}

		CCSPlayer & operator = (const CCSPlayer &player) throw()
		{
			m_playId = player.m_playId;
			m_playRole = player.m_playRole;
			m_userId = player.m_userId;
			m_userName = player.m_userName;
			m_playerCSName = player.m_playerCSName;
			m_killCount = player.m_killCount;
			m_bekillCount = player.m_bekillCount;
			m_playTime = player.m_playTime;
			return *this;
		}

		CCSPlayer & operator += (const CCSPlayer &player) throw()
		{
			m_playId = player.m_playId;
			m_playRole = player.m_playRole;
			m_userId = player.m_userId;
			m_userName = player.m_userName;
			m_playerCSName = player.m_playerCSName;
			m_killCount += player.m_killCount;
			m_bekillCount += player.m_bekillCount;
			m_playTime += player.m_playTime;
			return *this;
		}
	};

public:
//	CJoyCriticalSection	m_trenchLock;

	typedef CMap<UINT, UINT, CCSPlayer *, CCSPlayer * &> CCSPlayerIdMap;
	CCSPlayerIdMap	m_playerIdMap;

	typedef CList<CCSPlayer *> CSTrenchSort;
	CSTrenchSort	m_csTrenchSort;

public:
	CJoyCSTrench();
	~CJoyCSTrench();

	void SortPlayer(CCSPlayer * &player);
	void DelSortPlayer(CCSPlayer * &player);
	// added by lr 2005-05-23
	void SortPlayers();

	CJoyTransmitData * BuildCSTrench(); 
};

} // namespace JoyServer

#endif // __MSVR_CSTRENCH_H_SERVER_SVR_MAIN__